package com.guofen.controller.hsmpy;


import com.guofen.service.hsmpy.SamplingService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/hsmpy/Sampling")
@Controller
@Api(tags = "SamplingCntroller", description = "抽检")
public class SamplingController {

    @Autowired
    private SamplingService samplingService;

    @ApiOperation("将抽检是否合格及抽检备注写入数据库")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Result add(@ApiParam(name = "id", value = "id", required = true) @RequestParam String id,
                      @ApiParam(name = "is_qualified", value = "是否合格", required = true) @RequestParam String is_qualified,
                      @ApiParam(name = "inspection_remarks", value = "抽检备注", required = true) @RequestParam String inspection_remarks){
        Integer Id = Integer.parseInt(id);
        if (samplingService.add(Id, is_qualified, inspection_remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("添加失败");
    }


    @ApiOperation("根据“批次+组别+盒号”联合主键进行随机抽检num条记录")
    @RequestMapping(value = "/sample", method = RequestMethod.POST)
    @ResponseBody
    public Result sample(@ApiParam(name = "id", value = "id", required = true) @RequestParam String id,
                      @ApiParam(name = "num", value = "抽检数量", required = true) @RequestParam String num){
        Integer Num = Integer.parseInt(num);
        Integer Id = Integer.parseInt(id);
        return ResultGenerator.genSuccessResult(samplingService.sample(Id, Num));
    }

    @ApiOperation("返回可以进行抽检的记录")
    @RequestMapping(value = "/getlist", method = RequestMethod.GET)
    @ResponseBody
    public Result getlist(){
        return ResultGenerator.genSuccessResult(samplingService.getlist());
    }


}
